/*
 * Created By Visual Studio 2005
 * Create by: daqingshu
 * Create at: 2006-10-18 20:39:05{DATE}
 * Organization: BIT
 * 
 *
 */


using System;
using System.Collections.Generic;
using System.Text;

using Adge.Models;
using Adge.IDAL;
using NHibernate.Expression;
using Castle.ActiveRecord;

namespace Adge.SqlServerDAL
{
    public class AdgeArBase<T> : IAdgeArBase<T> where T : class
    {
        #region IAdgeArBase<T> Members
        public bool Create(T info)
        {
            try
            {
                ActiveRecordMediator<T>.Create(info);
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }

        public bool Update(T info)
        {
            try
            {
                ActiveRecordMediator<T>.Update(info);
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }

        public bool Save(T info)
        {
            try
            {
                //(info as ActiveRecordBase<T>).Save();
                ActiveRecordMediator<T>.Save(info);
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }

        public bool Delete(object Id)
        {
            try
            {
                T info = AdgeARBase<T>.Find(Id);
                (info as AdgeARBase<T>).Delete();
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }

        public T GetEntityById(object Id)
        {
            try
            {
                return AdgeARBase<T>.TryFind(Id);
            }
            catch (Exception)
            {
                throw;
            }
        }


        public T[] FindAll()
        {
            try
            {
                return AdgeARBase<T>.FindAll();
            }
            catch (Exception)
            {
                throw;
            }

        }


        /// <summary>
        /// Sliceds the find all.
        /// </summary>
        /// <param name="number">The number.</param>
        /// <param name="orderName">Name of the order.</param>
        /// <param name="filter">The filter.</param>
        /// <returns></returns>
        public T[] SlicedFindAll(int firstResult, int maxResults, Order[] orders, ICriterion[] criterias)
        {
            try
            {
                return AdgeARBase<T>.SlicedFindAll(firstResult, maxResults, orders, criterias);
            }
            catch (Exception)
            {
                throw;
            }
        }


        public bool DeleteAll()
        {
            try
            {
                AdgeARBase<T>.DeleteAll();
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }

        #endregion
    }
}
